from django.db import models
import django.utils.timezone as timezone
# Create your models here.

class y_yamllist(models.Model):
    y_id = models.BigAutoField(max_length=30, primary_key=True)
    yaml_name = models.CharField(max_length=255)
    yaml_directory = models.CharField(max_length=10000)
    yaml_describe = models.TextField(null=True)
    yaml_json = models.TextField()
    createTime = models.DateTimeField(default=timezone.now)
    modifyTime = models.DateTimeField(auto_now=True)
    is_using = models.IntegerField(default=0)
    is_delete = models.IntegerField(default=0)

    class Meta:
        db_table = "y_yamllist"
        # abstract = True

class y_yamlhosts(models.Model):
    h_id = models.BigAutoField(max_length=30, primary_key=True)
    host_ip = models.CharField(max_length=100, null=True)
    host_user = models.CharField(max_length=100, null=True)
    host_port = models.IntegerField(default=0)
    host_describ = models.CharField(max_length=255)
    createTime = models.DateTimeField(default=timezone.now)
    modifyTime = models.DateTimeField(auto_now=True)
    is_using = models.IntegerField(default=0)
    is_delete = models.IntegerField(default=0)

    class Meta:
        db_table = "y_yamlhosts"

class y_yamlkeys(models.Model):
    k_id = models.BigAutoField(max_length=30, primary_key=True)
    key_name = models.CharField(max_length=255)
    public_key = models.CharField(max_length=10000)
    private_key_file = models.CharField(max_length=10000)
    private_pwd = models.CharField(max_length=128)
    key_describ = models.TextField(null=True)
    createTime = models.DateTimeField(default=timezone.now)
    modifyTime = models.DateTimeField(auto_now=True)
    is_using = models.IntegerField(default=0)
    is_delete = models.IntegerField(default=0)


    class Meta:
        db_table = "y_yamlkeys"
        # abstract = True

class y_yamlgroup(models.Model):
    g_id = models.BigAutoField(max_length=30, primary_key=True)
    group_name = models.CharField(max_length=255)
    group_describ = models.TextField()
    associated_key = models.ManyToManyField(y_yamlkeys)
    associated_host = models.ManyToManyField(y_yamlhosts)
    createTime = models.DateTimeField(default=timezone.now)
    modifyTime = models.DateTimeField(auto_now=True)
    is_using = models.IntegerField(default=0)
    is_delete = models.IntegerField(default=0)


    class Meta:
        db_table = "y_yamlgroup"
        # abstract = True

class r_group_rules(models.Model):
    r_id = models.BigAutoField(max_length=30, primary_key=True)
    g_id = models.BigIntegerField()
    group_rules = models.TextField()
    createTime = models.DateTimeField(default=timezone.now)
    modifyTime = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = "r_group_rules"

class y_history(models.Model):
    id = models.BigAutoField(max_length=30, primary_key=True)
    h_type = models.IntegerField()
    exe_user = models.CharField(max_length=255, null=True)
    exe_group = models.CharField(max_length=255)
    exe_shell = models.CharField(max_length=255, null=True)
    exe_playbook = models.CharField(max_length=255, null=True)
    exe_value = models.CharField(max_length=255,null=True)
    exe_rule = models.CharField(max_length=255, null=True)
    exe_rule_file = models.CharField(max_length=255, null=True)
    exe_results = models.TextField()
    exe_status = models.IntegerField(default=0)
    createDate = models.DateTimeField(default=timezone.now)

    class Meta:
        db_table = "y_history"